package com.woniuxy.products.service.impl;

import com.woniuxy.commons.entity.PageBean;
import com.woniuxy.commons.entity.Products;
import com.woniuxy.commons.utils.ResponseResult;
import com.woniuxy.commons.utils.ResultStatus;
import com.woniuxy.products.entity.ProductsAndRateAndRepayment;
import com.woniuxy.products.mapper.ProductsMapper;
import com.woniuxy.products.service.ProductsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author author
 * @create 2021-11-16 15:00
 */
@Service
public class ProductsServiceImpl implements ProductsService {

    @Resource
    private ProductsMapper productsMapper;
    //添加产品
    @Override
    public boolean addProducts(Products products) {
        return productsMapper.insertProducts(products);
    }

    @Override
    public ResponseResult<PageBean<Products>> selectProductsByPage(ProductsAndRateAndRepayment productsAndRateAndRepayment, int pageIndex, int pageSize) {
        PageBean<Products> pageBean = new PageBean<>();
        List<Products> productss = productsMapper.selectProductsByPage(productsAndRateAndRepayment, pageIndex, pageSize);
//        得到数据条数
        int i = productsMapper.selectCountProductsByPage(productsAndRateAndRepayment);

        pageBean.setPageIndex(pageIndex);
        pageBean.setPageSize(pageSize);
        pageBean.setBeanList(productss);
        pageBean.setTotalRecord(i);

        ResponseResult<PageBean<Products>> result = new ResponseResult<>();
        result.setCode(200);
        result.setMessage("成功");
        result.setStatus(ResultStatus.SELECT_YES);
        result.setData(pageBean);

        return result;
    }

    //修改表中数据
    @Override
    public void updateProductsService(Products products) {
        productsMapper.updateByProducts(products);
    }

    //删除表中数据根据id
    @Override
    public void deleteByPidService(String pid) {
        productsMapper.deleteByPid(pid);
    }


}
